﻿/*
 * Copyright(C) 2012,ajayumi 保留所有权利。( All rights reserved. )
 * 
 * 文件名称：JQueryGridSoptCollection.cs
 * 摘    要：
 * 当前版本：1.0
 * 作    者：黄乙冬 (ajayumi)
 * 创建日期：2012年6月2日星期六
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ajayumi.Platform.Web.Controls.DataGrid
{
    internal static class JQueryGridSopt
    {
        internal static string Builder(JQueryGridFilter filter)
        {
            StringBuilder sb = new StringBuilder();

            //等于       eq         =              
            //不等于     ne         <> 
            //小于       lt         < 
            //小于等于   le         <= 
            //大于       gt         > 
            //大于等于   ge         >= 
            //以*开头    bw         like 
            //不以*开头  bn         not like 
            //在         in         in 
            //不在       ni         not in 
            //以*结尾    ew         like 
            //不以*结尾  en         not like 
            //包含       cn         like 
            //不包含     nc         not like k

            foreach (JQueryGridFilterRules item in filter.JQueryGridFilterRulesList)
            {
                sb.AppendFormat(" {0} ", filter.GroupOp);
                switch (item.Op)
                {
                    case "eq":
                        sb.AppendFormat(" {0} = '{1}' ", item.Field, item.Data);
                        break;
                    case "ne":
                        sb.AppendFormat(" {0} <> '{1}' ", item.Field, item.Data);
                        break;
                    case "lt":
                        sb.AppendFormat(" {0} < '{1}' ", item.Field, item.Data);
                        break;
                    case "le":
                        sb.AppendFormat(" {0} <= '{1}' ", item.Field, item.Data);
                        break;
                    case "gt":
                        sb.AppendFormat(" {0} > '{1}' ", item.Field, item.Data);
                        break;
                    case "ge":
                        sb.AppendFormat(" {0} >= '{1}' ", item.Field, item.Data);
                        break;
                    case "bw":
                        sb.AppendFormat(" {0} like '*{1}' ", item.Field, item.Data);
                        break;
                    case "bn":
                        sb.AppendFormat(" {0} not like '*{1}' ", item.Field, item.Data);
                        break;
                    case "in":
                        sb.AppendFormat(" {0} in '{1}' ", item.Field, item.Data);
                        break;
                    case "ni":
                        sb.AppendFormat(" {0} not in '{1}' ", item.Field, item.Data);
                        break;
                    case "ew":
                        sb.AppendFormat(" {0} like '{1}*' ", item.Field, item.Data);
                        break;
                    case "en":
                        sb.AppendFormat(" {0} not like '{1}*' ", item.Field, item.Data);
                        break;
                    case "cn":
                        sb.AppendFormat(" {0} like '%{1}%' ", item.Field, item.Data);
                        break;
                    case "nc":
                        sb.AppendFormat(" {0} not like '%{1}%' ", item.Field, item.Data);
                        break;
                }
            }

            return sb.ToString();
        }


    }
}
